<?php

namespace app\controller\v1;

use app\model\VendorsModel;
use app\validate\VendorsValidate;

class Vendors extends System
{
    /**
     * Notes: 分页列表
     * User: chenLei
     * 10/15/25 10:52:13
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function list()
    {
        $vendorsModel = new VendorsModel();
        $res = $vendorsModel->list($this->params);
        return $this->successJson('ok', $res);
    }


    /**
     * Notes: 添加
     * User: chenLei
     * 10/15/25 10:52:13
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function add()
    {
        $validate = new VendorsValidate();
        if (!$validate->scene('add')->check($this->params)) return $this->errorJson($validate->getError());

        $vendorsModel = new VendorsModel();
        $res = $vendorsModel->add($this->params);
        if ($res === false) return $this->errorJson($vendorsModel->getError());
        return $this->successJson('ok', $res);
    }


    /**
     * Notes: 编辑
     * User: chenLei
     * 10/15/25 10:57:14
     * @return \think\response\Json
     */
    public function edit()
    {
        $validate = new VendorsValidate();
        if (!$validate->scene('edit')->check($this->params)) return $this->errorJson($validate->getError());

        $vendorsModel = new VendorsModel();
        $res = $vendorsModel->edit($this->params);
        if ($res === false) return $this->errorJson($vendorsModel->getError());
        return $this->successJson('ok', $res);
    }


    /**
     * Notes: 删除
     * User: chenLei
     * 10/15/25 10:57:14
     *
     * @return \think\response\Json
     */

    public function del()
    {
        $validate = new VendorsValidate();
        if (!$validate->scene('del')->check($this->params)) return $this->errorJson($validate->getError());
        $vendorsModel = new VendorsModel();
        $res = $vendorsModel->del($this->params);
        if ($res === false) return $this->errorJson($vendorsModel->getError());
        return $this->successJson('ok', $res);
    }

    /**
     * Notes: 修改密码
     * User: chenLei
     * 10/15/25 10:58:38
     * @return \think\response\Json
     */
    public function editPassword()
    {
        $validate = new VendorsValidate();
        if (!$validate->scene('editPassword')->check($this->params)) return $this->errorJson($validate->getError());

        $vendorsModel = new VendorsModel();
        $res = $vendorsModel->editPassword($this->params);
        if ($res === false) return $this->errorJson($vendorsModel->getError());
        return $this->successJson('ok', $res);
    }

}